<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>i2c: C:/Users/Jon/Downloads/OOP/db-control/dbCategory.php Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">i2c
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">C:/Users/Jon/Downloads/OOP/db-control/dbCategory.php</div>  </div>
</div>
<div class="contents">
<a href="db_category_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00002"></a>00002 
<a name="l00025"></a><a class="code" href="classdb_category.html">00025</a> <span class="keyword">class </span><a class="code" href="classdb_category.html">dbCategory</a> {
<a name="l00026"></a>00026 
<a name="l00027"></a><a class="code" href="classdb_category.html#aea6c4d653e217f31256ded5783ed58f4">00027</a>    <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_category.html#aea6c4d653e217f31256ded5783ed58f4">createTable</a>() {
<a name="l00028"></a>00028       <span class="comment">//create table category</span>
<a name="l00029"></a>00029       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;</span>
<a name="l00030"></a>00030 <span class="stringliteral">        create table category(</span>
<a name="l00031"></a>00031 <span class="stringliteral">            categoryID      int             NOT NULL AUTO_INCREMENT,</span>
<a name="l00032"></a>00032 <span class="stringliteral">            categoryName    varchar(45)     NOT NULL,</span>
<a name="l00033"></a>00033 <span class="stringliteral">            constraint PK_Category PRIMARY KEY(categoryID)</span>
<a name="l00034"></a>00034 <span class="stringliteral">            );</span>
<a name="l00035"></a>00035 <span class="stringliteral">&quot;</span>;
<a name="l00036"></a>00036       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00037"></a>00037       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00038"></a>00038       mysql_close();
<a name="l00039"></a>00039       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00040"></a>00040          echo mysql_error();
<a name="l00041"></a>00041          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00042"></a>00042       }
<a name="l00043"></a>00043       <span class="comment">//mysql_close();</span>
<a name="l00044"></a>00044       <span class="comment">//Previous query was successful</span>
<a name="l00045"></a>00045       <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00046"></a>00046    }
<a name="l00047"></a>00047 
<a name="l00052"></a><a class="code" href="classdb_category.html#a772b8c55b241668e6031bb263f5d832f">00052</a>    <span class="keyword">function</span> <a class="code" href="classdb_category.html#a772b8c55b241668e6031bb263f5d832f">getAllCategories</a>() {
<a name="l00053"></a>00053       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT * FROM category&quot;</span>;
<a name="l00054"></a>00054       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00055"></a>00055       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00056"></a>00056 
<a name="l00057"></a>00057       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00058"></a>00058          echo mysql_error();
<a name="l00059"></a>00059          mysql_close();
<a name="l00060"></a>00060          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00061"></a>00061       }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063       <span class="comment">//Query was successful.</span>
<a name="l00064"></a>00064       <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00065"></a>00065    }
<a name="l00066"></a>00066 
<a name="l00073"></a><a class="code" href="classdb_category.html#a4fb22ba86a2ad867f7e5ecd1b62e265f">00073</a>    <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_category.html#a4fb22ba86a2ad867f7e5ecd1b62e265f">addCategory</a>($c, &amp;$id) {
<a name="l00074"></a>00074       <span class="keywordflow">if</span> (!$c instanceof <a class="code" href="class_category.html">Category</a>) {
<a name="l00075"></a>00075          echo (<span class="stringliteral">&quot;Invalid arguement insertInto ( ) function&lt;br /&gt;&quot;</span>);
<a name="l00076"></a>00076          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00077"></a>00077       }
<a name="l00078"></a>00078       <span class="comment">//Compose the INSERT INTO query srting. Primary keyvalue is missing.</span>
<a name="l00079"></a>00079       <span class="comment">//Database server automatically generates a unique ID for the primary</span>
<a name="l00080"></a>00080       <span class="comment">//key.</span>
<a name="l00081"></a>00081       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;INSERT INTO category VALUES (null, &#39;%s&#39;)&quot;</span>, $c-&gt;getCategoryName()
<a name="l00082"></a>00082       );
<a name="l00083"></a>00083       <span class="comment">//printf(&quot;-&gt;Query: %s &lt;br /&gt;&quot;, $query);</span>
<a name="l00084"></a>00084       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00085"></a>00085       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00086"></a>00086       $id = mysql_insert_id();
<a name="l00087"></a>00087       mysql_close();
<a name="l00088"></a>00088       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00089"></a>00089          echo mysql_error();
<a name="l00090"></a>00090          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00091"></a>00091       }
<a name="l00092"></a>00092       <span class="comment">//query was successful.</span>
<a name="l00093"></a>00093       <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00094"></a>00094    }
<a name="l00095"></a>00095 
<a name="l00101"></a><a class="code" href="classdb_category.html#a86e23bd1f4d5b3b616ea11b6ac2d1c8c">00101</a>    <span class="keyword">function</span> <a class="code" href="classdb_category.html#a86e23bd1f4d5b3b616ea11b6ac2d1c8c">checkCategoryID</a>($c) {
<a name="l00102"></a>00102       <span class="keywordflow">if</span> (!($c instanceof <a class="code" href="class_category.html">Category</a>)) {
<a name="l00103"></a>00103          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00104"></a>00104       }
<a name="l00105"></a>00105       $categoryID = $c-&gt;getCategoryID();
<a name="l00106"></a>00106       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00107"></a>00107       <span class="keywordflow">if</span> (mysql_num_rows(mysql_query(<span class="stringliteral">&quot;SELECT * FROM category WHERE</span>
<a name="l00108"></a>00108 <span class="stringliteral">                categoryID=$categoryID&quot;</span>)) == <span class="keyword">false</span>) {
<a name="l00109"></a>00109          mysql_close();
<a name="l00110"></a>00110          <span class="comment">//nothing existsmysql_num_rows</span>
<a name="l00111"></a>00111          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00112"></a>00112       } <span class="keywordflow">else</span> {
<a name="l00113"></a>00113          <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00114"></a>00114       }
<a name="l00115"></a>00115    }
<a name="l00116"></a>00116 
<a name="l00122"></a><a class="code" href="classdb_category.html#a7fc3d9a38dbf98b9cce2961e298a9a86">00122</a>    <span class="keyword">function</span> <a class="code" href="classdb_category.html#a7fc3d9a38dbf98b9cce2961e298a9a86">getCategoryID</a>($c) {
<a name="l00123"></a>00123       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<span class="stringliteral">&quot;SELECT categoryID from Category WHERE</span>
<a name="l00124"></a>00124 <span class="stringliteral">            categoryID=&#39;$c&#39;&quot;</span>);
<a name="l00125"></a>00125       $row = mysql_fetch_row(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00126"></a>00126       <span class="keywordflow">return</span> $row[<span class="charliteral">&#39;0&#39;</span>];
<a name="l00127"></a>00127    }
<a name="l00128"></a>00128 
<a name="l00134"></a><a class="code" href="classdb_category.html#af9a3ee1cae55fca49cdd6f9cc325a011">00134</a>    <span class="keyword">function</span> <a class="code" href="classdb_category.html#af9a3ee1cae55fca49cdd6f9cc325a011">getCategoryName</a>($c) {
<a name="l00135"></a>00135       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT categoryName FROM category WHERE categoryID=&#39;$c&#39;&quot;</span>;
<a name="l00136"></a>00136       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00137"></a>00137       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00138"></a>00138       mysql_close();
<a name="l00139"></a>00139       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00140"></a>00140          echo mysql_error();
<a name="l00141"></a>00141          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00142"></a>00142       }
<a name="l00143"></a>00143       <span class="comment">//Query was successful.</span>
<a name="l00144"></a>00144       <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00145"></a>00145    }
<a name="l00146"></a>00146 
<a name="l00152"></a><a class="code" href="classdb_category.html#a9287137c4ed5d2383f8e098d7d8ce286">00152</a>    <span class="keyword">function</span> <a class="code" href="classdb_category.html#a9287137c4ed5d2383f8e098d7d8ce286">deleteCategoryID</a>($c) {
<a name="l00153"></a>00153       <span class="keywordflow">if</span> (!($c instanceof <a class="code" href="class_category.html">Category</a>)) {
<a name="l00154"></a>00154          echo (<span class="stringliteral">&quot;Invalid argument deleteFrom( ) function&lt;br /&gt;&quot;</span>);
<a name="l00155"></a>00155          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00156"></a>00156       }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158       <span class="comment">//Compose the DELETE FROM query string.</span>
<a name="l00159"></a>00159       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;DELETE FROM category WHERE categoryID = %d&quot;</span>, $c-&gt;getCategoryID()
<a name="l00160"></a>00160       );
<a name="l00161"></a>00161       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00162"></a>00162       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00163"></a>00163       mysql_close();
<a name="l00164"></a>00164       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00165"></a>00165          echo mysql_error();
<a name="l00166"></a>00166          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00167"></a>00167       }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169       <span class="comment">//Query was successful.</span>
<a name="l00170"></a>00170       <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00171"></a>00171    }
<a name="l00172"></a>00172 
<a name="l00176"></a><a class="code" href="classdb_category.html#aaaca33ac319178544c7cc9df0d9f1578">00176</a>    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_category.html#aaaca33ac319178544c7cc9df0d9f1578">getAllByID</a>($id, &amp;$output) {
<a name="l00177"></a>00177       <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;SELECT categoryName FROM category WHERE </span>
<a name="l00178"></a>00178 <span class="stringliteral">            categoryID=%d&quot;</span>, $id);
<a name="l00179"></a>00179       <span class="comment">//printf(&quot;-&gt;Query: %s&lt;br /&gt;&quot;, $query);</span>
<a name="l00180"></a>00180       <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00181"></a>00181       <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00182"></a>00182       mysql_close();
<a name="l00183"></a>00183 
<a name="l00184"></a>00184       <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00185"></a>00185          $output = sprintf(<span class="stringliteral">&quot;%s&quot;</span>, mysql_error());
<a name="l00186"></a>00186          <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00187"></a>00187       }
<a name="l00188"></a>00188       <span class="comment">//process result and print out warning or attribute values</span>
<a name="l00189"></a>00189       <span class="keywordflow">return</span> dbCategory::checkForOneInstance(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>, $id, $output);
<a name="l00190"></a>00190    }
<a name="l00191"></a>00191 
<a name="l00197"></a>00197    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">function</span> checkForOneInstance(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>, $id, &amp;$output) {
<a name="l00198"></a>00198       <span class="comment">//Local variables are initialized</span>
<a name="l00199"></a>00199       $errorStatus = <span class="keyword">false</span>;
<a name="l00200"></a>00200 
<a name="l00201"></a>00201       $howMany = mysql_num_rows(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00202"></a>00202       <span class="comment">//printf(&quot;--&gt;Found %d instance(s) for categoryID=%d.&lt;br /&gt;, $howMany, $id);</span>
<a name="l00203"></a>00203       <span class="keywordflow">switch</span> ($howMany) {
<a name="l00204"></a>00204          <span class="keywordflow">case</span> 0:
<a name="l00205"></a>00205             $output = sprintf(<span class="stringliteral">&quot;No Category instance with ID=%d was found.&quot;</span>, $id);
<a name="l00206"></a>00206             $errorStatus = <span class="keyword">true</span>;
<a name="l00207"></a>00207             <span class="keywordflow">break</span>;
<a name="l00208"></a>00208          <span class="keywordflow">case</span> 1:
<a name="l00209"></a>00209             <span class="comment">//mysql_fetch() DOES NOT return primary key values</span>
<a name="l00210"></a>00210             $output = mysql_fetch_assoc(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00211"></a>00211             <span class="comment">//printf(&quot;-&gt;output: %s&lt;br /&gt;&quot;, $output[&#39;categoryName&#39;]);</span>
<a name="l00212"></a>00212             $errorStatus = <span class="keyword">false</span>;
<a name="l00213"></a>00213             <span class="keywordflow">break</span>;
<a name="l00214"></a>00214          <span class="keywordflow">default</span>:
<a name="l00215"></a>00215             $output = sprintf(<span class="stringliteral">&quot;There are multiple Category instances with</span>
<a name="l00216"></a>00216 <span class="stringliteral">                                   ID=%d.&quot;</span>, $id);
<a name="l00217"></a>00217             $errorStatus = <span class="keyword">true</span>;
<a name="l00218"></a>00218             <span class="keywordflow">break</span>;
<a name="l00219"></a>00219       }
<a name="l00220"></a>00220       <span class="keywordflow">return</span> $errorStatus;
<a name="l00221"></a>00221    }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 ?&gt;
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Tue Nov 29 2011 18:18:54 for i2c by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
